<template>
  <div>
    <div class="top">
      <img src="http://124.223.73.204:8080/img/profile/bg.png" alt="">
      <div class="user" v-if="userDataList.nickname">
        <div class="profile-photo">
          <img :src="'http://124.223.73.204:8080'+userDataList.avatar" alt="">
        </div>
          <p class="id">{{userDataList.nickname}}</p>
      <van-button type="primary" round  size="mini" @click="loginout">退出</van-button>
      <p class="change">编辑个人资料 <van-icon name="play" /></p>
      </div>
      <div class="visitor" v-else>
        <div class="profile-photo">
          <img src="http://124.223.73.204:8080/img/profile/avatar.png" alt="">
        </div>
          <p>游客</p>
      <van-button type="primary"  @click="$router.push('/login')">去登录</van-button>
      </div>
    </div>
<nav>
  <van-grid :border="false" :column-num="3" :gutter="13">
  <van-grid-item icon="star-o" text="我的收藏" />
  <van-grid-item icon="wap-home-o" text="我的出租" />
  <van-grid-item icon="underway-o" text="看房记录" />
  <van-grid-item icon="vip-card-o" text="成为房主" />
  <van-grid-item icon="contact" text="个人资料" />
  <van-grid-item icon="service-o" text="联系我们" />
</van-grid>
</nav>
<div class="image">
  <img src="http://124.223.73.204:8080/img/profile/join.png" alt="">
</div>
  </div>

</template>

<script>
import { Dialog } from 'vant'
import { getToken, removeToken } from '@/utils/storage'
import { getUserData } from '@/api/user'
export default {
  name: 'MyIndex',
  data () {
    return {
      token: '',
      userDataList: ''
    }
  },
  methods: {
    loginout () {
      Dialog.confirm({
        title: '提示',
        message: '确认是否退出'
      })
        .then(() => {
          removeToken()
          this.userDataList = ''
        })
        .catch(() => {

        })
    }
  },
  async created () {
    this.token = getToken()
    if (this.token) {
      const res = await getUserData(this.token)
      this.userDataList = res.data.body
    }
  }
}
</script>

<style lang="less" scoped>
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.top{
  position: relative;

  img{
    width: 100%;
  }
  .visitor{
    position: absolute;
    background: #fff;
    width: 85%;
    height: 165px;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0px 0px 10px 3px #ddd;
    margin: 0 auto -105px;
    padding: 0 20px;
    padding-top: 0;
    text-align: center;
    font-size: 13px;
    .profile-photo{
    position: relative;
    transform: translateY(-50%);
    border-radius: 50%;
    width: 70px;
    height: 70px;
    border: solid 5px #f5f5f5;
    display: inline-block;
    box-shadow: 0px 2px 2px #bdbdbd;
      img{
        width: 100%;
        height: 100%;
      }
    }
  p{
      margin-top: -17px;
      margin-bottom: 20px;
    }
     /deep/   .van-button{
        width: 69px;
        height: 30px;
    }
  }
   .user{
    position: absolute;
    background: #fff;
    width: 85%;
    height: 165px;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0px 0px 10px 3px #ddd;
    margin: 0 auto -105px;
    padding: 0 20px;
    padding-top: 0;
    text-align: center;
    font-size: 13px;
    .profile-photo{
    position: relative;
    transform: translateY(-50%);
    border-radius: 50%;
    width: 70px;
    height: 70px;
    border: solid 5px #f5f5f5;
    display: inline-block;
    box-shadow: 0px 2px 2px #bdbdbd;
      img{
        width: 100%;
        height: 100%;
      }
    }
    .id{
      margin-top: -17px;
      margin-bottom: 5px;
    }
 /deep/   .van-button{
        width: 54px;
        height: 20px;
    }
  .change{
    color: #999;
    font-size: 12px;
    margin-top: 25px;
    }
  }
}
nav{
  margin-top: 110px;
 /deep/ .van-grid-item__text{
    font-size: 13px;
    color: #333;
  }
   /deep/ .van-grid-item__icon{
    font-size: 23px
   }
}
.image{
  margin: 15px auto 0;
  width: 345px;
  height: 85px;
  img{
    width: 100%;
    height: 100%;
  }
}
</style>
